package reflect;

import java.lang.reflect.Method;

/**
 * 调用有参方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        //调用Person的say(String)
        Method method = cls.getMethod("say",String.class);//say(String)
        method.invoke(obj,"hehe");//p.say("hehe");

        //调用say(String,int)
        Method method1 = cls.getMethod("say", String.class, int.class);
        method1.invoke(obj,"哈哈",5);
    }
}









